<?php

class MembersController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
    }

    public function signupAction()
    {
        $form = new Form_Signup();
        if (
            $this->getRequest()->isPost() &&
            $form->isValid($this->getRequest()->getPost())
        ) {
           $member = $form->save();
           $this->_helper->mailer->send($member->email, 'confirm-registration', $member->toArray());
           $this->_helper->messenger->success('account_has_been_created');
           $this->_redirect('/');
        }
        $this->view->form = $form;
    }

    public function activateAction()
    {
        if (
            null == ($token = explode(':', base64_decode($this->_getParam('key')))) ||
            !is_array($token)
        ) {
            $this->_helper->error->noPermissions();
        }

        $member = Ext_App::getTable('Model_DbTable_Member')->findById($token[0]);

        if (!$member || $member->status != Model_Member::STATUS_NOT_VERIFIED) {
            $this->_helper->error->notFound();
        }

        if ($token[1] == $member->verify_key) {
            $member->activate();
            Zend_Auth::getInstance()->getStorage()->write($member->simplify());
            $this->_helper->messenger->success('your_email_has_been_confirmed');
            $this->_helper->redirector->gotoSimple('index', 'index', 'default');
        } else {
            $this->_helper->messenger->error('wrong_confirmation_key');
            $this->_helper->redirector->gotoSimple('index', 'index', 'default');
        }
    }
}



